package com.seashop.init;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.seashop.entity.SystemConfig;
import com.seashop.enums.SystemConfigEnum;
import com.seashop.mapper.SystemConfigMapper;
import com.seashop.redis.RedisZero;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author moredln
 * @desc 初始化系统配置文件到redis
 * @date 2020-11-02 15:06
 */
@Component
@Slf4j
public class InitSystemConfig {

    @Autowired
    private SystemConfigMapper systemConfigMapper;
    @Autowired
    private RedisZero redisZero;

    @PostConstruct
    public void init() {
        log.info("SystemConfig init start ....");
        List<SystemConfig> systemConfigs = systemConfigMapper.selectList(new QueryWrapper<SystemConfig>().eq("belong", SystemConfigEnum.GENERAL));
        if (!systemConfigs.isEmpty()) {
            for (SystemConfig systemConfig : systemConfigs) {
                redisZero.set("systemConfig:" + systemConfig.getConfigName(), systemConfig.getConfigValue());
            }
        }
        log.info("SystemConfig init end ....");
    }


}
